import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {
    public static User login() {
        System.out.println("请输入用户名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.next();
        System.out.println("请输入你的身份");
        System.out.println("1. 管理员 == 2. 用户");
        int choice = scanner.nextInt();
        while (true) {
            switch (choice) {
                case 1:
                    return new AdminUser(name);
                case 2:
                    return new NormalUser(name);
                default:
                    System.out.println("输入错误");
                    break;
            }
        }
    }
    public static void main(String[] args) {
        BookList booklist = new BookList();
        //user指向哪个对象，看返回值是什么
        User user = login();
        while (true) {
            int choice = user.menu();
            if (choice < 0 || choice > 4) {
                System.out.println("输入错误");
                continue;
            }
            System.out.println("你选择的是：" + choice);
            if (choice == 0) {
                System.out.println("退出系统");
                break;
            }
            user.doOperation(choice, booklist);
        }
    }
}
